package cn.bonoon.services.plugins;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.bonoon.core.plugins.FaqService;
import cn.bonoon.entities.interacting.FaqEntity;
import cn.bonoon.kernel.support.IOperator;
import cn.bonoon.kernel.support.services.AbstractService;

@Service
@Transactional(readOnly = true)
public class FaqServiceImpl extends AbstractService<FaqEntity> implements FaqService {
//
//	@Override
//	public List<FaqEntity> faqs(IOperator opt) {
//		return __list(domainClass, "select x from FaqEntity x where x.creatorId=?", opt.getId());
//	}

	@Override
	@Transactional
	public void changeReleaseStatus(IOperator user, Long id) {
		FaqEntity entity = entityManager.find(FaqEntity.class, id);
		entity.setDisable(!entity.isDisable());
		entityManager.merge(entity);
	}

	@Override
	public List<FaqEntity> faqs(IOperator opt, String key, Long id) {
		String ql = "select x from FaqEntity x where x.disable=false and x.catalog.disable=false and x.catalog.id=? ";
		ql += "and (x.catalog.ownerId=0 or x.catalog.ownerId=?) order by x.ordinal asc";
		return __list(FaqEntity.class, ql, id, opt.getOwnerId());
		//return __list(domainClass, "select x from FaqEntity x where x.key=? and (x.ownerId=? or x.ownerId is null or x.ownerId=0)", key, opt.getOwnerId());
	}
}
